import React, { Component } from 'react'
import {Switch,Route,Redirect} from 'react-router-dom'
// import {asyncRoutes} from './routes'
import FrameLayout from './layout'
import { connect } from 'react-redux'
 @connect((state)=>({
   token:state.user.token,
   routes:state.user.routes
 }))
class App extends Component {
  
  render() {
    console.log('app组件：', JSON.stringify(this.props.routes))
    return (
      this.props.token?
      <FrameLayout>
        <Switch>
          {
            this.props.routes.map(route => (
              <Route key={route.path} path={route.path} component={route.component} />
            ))
          }
          <Redirect from="/admin" to="/admin/dashboard" exact />
          <Redirect to="/404" />
        </Switch>
      </FrameLayout>
      :
      <Redirect to="/login"/>
    )
  }
}
export default App